﻿// -----------------------------------------------------------------------
// <copyright file="ViewModelLocator.cs" company="Christoph van der Fecht">
// This code can be used in Comercial, free and opensource projects
// </copyright>
// -----------------------------------------------------------------------

namespace MediaTool.ViewModel
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using GalaSoft.MvvmLight;


    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ViewModelLocator
    {
        /// <summary>
        /// Instance of the <see cref="ImageArrangerViewModel"/> class.
        /// </summary>
        private static ImageArrangerViewModel ImageArrangerViewModel;

        /// <summary>
        /// Instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        private static MainViewModel MainViewModel;

        /// <summary>
        /// Initializes a new instance of the <see cref="ViewModelLocator"/> class.
        /// </summary>
        public ViewModelLocator()
        {
        }

        /// <summary>
        /// Gets an instance of the <see cref="ImageArrangerViewModel"/> class.
        /// </summary>
        public static ImageArrangerViewModel ImageArranger
        {
            get
            {
                if (ImageArrangerViewModel == null)
                {
                    CreateImagearrangerViewModel();
                }

                return ImageArrangerViewModel;
            }
        }

        /// <summary>
        /// Gets an instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public static MainViewModel MainView
        {
            get
            {
                if (MainViewModel == null)
                {
                    CreateMainViewModel();
                }

                return MainViewModel;
            }
        }

        /// <summary>
        /// Cleans all resources used by the view models.
        /// </summary>
        public void Cleanup()
        {
            this.CleanImageArrangerViewModel();
            this.CleanMainViewModel();
        }

        /// <summary>
        /// Generates a new instance of the <see cref="ImagearrangerViewModel"/> class.
        /// </summary>
        private static void CreateImagearrangerViewModel()
        {
            if (ImageArrangerViewModel == null)
            {
                ImageArrangerViewModel = new ImageArrangerViewModel();
            }
        }

        /// <summary>
        /// Generates a new instance of the <see cref="MainViewModel"/>
        /// </summary>
        private static void CreateMainViewModel()
        {
            if (MainViewModel == null)
            {
                MainViewModel = new MainViewModel();
            }
        }

        /// <summary>
        /// Cleans all resources used by the <see cref="ImageArrangerViewModel"/> class.
        /// </summary>
        private void CleanImageArrangerViewModel()
        {
            if (ImageArrangerViewModel != null)
            {
                ImageArrangerViewModel.Cleanup();
            }
        }

        /// <summary>
        /// Cleans all resources used by the <see cref="MainViewModel"/> class.
        /// </summary>
        private void CleanMainViewModel()
        {
            if (MainViewModel != null)
            {
                MainViewModel.Cleanup();
            }
        }
    }
}
